package cpa.prowon.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;

import cpa.prowon.Application;
import cpa.prowon.gui.MainWindow;
import cpa.prowon.gui.util.ImageUtil;

/**
 * The patched action standardizes the functionality for language patching. It has to be
 * subclassed to imlpement real action functionality. Subclasses have to implement the
 * methods to return the key information for tooltips, titles etc.  
 * @author Chris
 */
abstract class PatchedAction extends Action {

	// Properties
	protected MainWindow window;

	// The abstract methods which have to be implemented in the subclasses
	abstract protected String getTitleKey();
	abstract protected String getTooltipKey();
	abstract protected String getImageKey();
	
	/**
	 * Return the title
	 * @return The title of the action
	 * @author Chris
	 */
	protected String getTitle() {
		return "";
	}

	/**
	 * Do the initialization of the action, which is setting the title, tooltip and image
	 * @author Chris
	 */
	protected void initialize() {
		
		// Set the title
		if (getTitle() != "") {
			setText(getTitle());
		} else if (getTitleKey() != "") {
			setText(Application.getInstance().getResourceBundle().getString(getTitleKey()));
		}
		
		// Set the tooltip
		if (getTooltipKey() != "" ) {
			setToolTipText(Application.getInstance().getResourceBundle().getString(getTooltipKey()));
		}
		
		// Set the image
		if (getImageKey() != "") {
			setImageDescriptor(
				ImageDescriptor.createFromURL(ImageUtil.getURL(getImageKey()))
				);
		}
		
	}
	
	/**
	 * Protected Constructor
	 * @author Chris
	 */
	protected PatchedAction() {
		super();
	}

	/**
	 * Constructor for PatchedAction.
	 * @param MainWindow The main window where the action is used
	 * @author Chris
	 */
	public PatchedAction(MainWindow w) {
		
		// Call the super constructor
		super();
		
		// Remember the application window
		window = w;
		
		// Do the initialization work
		initialize();
		
	}

}
